package com.forum.controller.admin;

import com.forum.constant.MessageConstant;
import com.forum.dto.ThreadUpdateDTO;
import com.forum.dto.ThreadsPageQueryDTO;
import com.forum.result.PageResult;
import com.forum.result.Result;
import com.forum.service.ThreadsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "帖子接口")
@RestController("AdminThreadsController")
@RequestMapping("/admin/threads")
@Slf4j
public class ThreadsController {

    @Autowired
    private ThreadsService threadsService;

    @ApiOperation("帖子查询")
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody ThreadsPageQueryDTO threadsPageQueryDTO){
        PageResult pageResult = threadsService.pageQuery(threadsPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("帖子是否置顶")
    @PutMapping("/{id}/{isSticky}")
    public Result updateSticky(@PathVariable Long id, @PathVariable Integer isSticky){
        log.info("获取到的数据，{},{}", id, isSticky);
        threadsService.updateByIdIsSticky(id, isSticky);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }
    @ApiOperation("帖子是否封贴")
    @PutMapping
    public Result updateById(@RequestBody ThreadUpdateDTO threadUpdateDTO){
        log.info("获取到的数据，{}", threadUpdateDTO);
        threadsService.updateByIdIsLocked(threadUpdateDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @ApiOperation("帖子删除")
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable("id") Long id){
        threadsService.deleteById(id);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }
}
